﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

namespace CSE445HW5.UserProtected
{
    public partial class TodoPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string description = textboxDescription.Text;
            textDate.Text = DateTime.Now.Date.ToShortDateString();

            if (Session.Count != 0)
            {
                if(taskListBox.Items.Count == 0)
                {
                    ArrayList taskList = (ArrayList)Session["tasks"];

                    foreach (Task t in taskList)
                    {
                        string task = t._Description + "     (" + t._Date + ")";
                        taskListBox.Items.Add(task);
                    }
                }
            }
            else
            {
                ArrayList taskList = new ArrayList();
                Session["tasks"] = taskList;
            }
        }

        protected void addTaskButton_Click(object sender, EventArgs e)
        {
            string description = textboxDescription.Text;
            if (description != "")
            {
                string date = textDate.Text;
                Task task = new Task(description, date);

                ArrayList taskList;

                if (Session.Count != 0)
                {
                    taskList = (ArrayList)Session["tasks"];
                }
                else
                {
                    taskList = new ArrayList();          
                }

                taskList.Add(task);
                Session["tasks"] = taskList;
                string taskStr = description + "    (" + date + ")";
                taskListBox.Items.Add(taskStr);
            }     
        }

        protected void dateCalendar_SelectionChanged(object sender, EventArgs e)
        {
            textDate.Text = dateCalendar.SelectedDate.ToShortDateString();
        }
    }

    public class Task
    {
        public string _Description;
        public string _Date;

        public Task(string description, string date)
        {
            _Description = description;
            _Date = date;
        }

    }
}